package edu.uow.scsse.gui;

import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.table.DefaultTableModel;

import edu.uow.scsse.main.DriverMain;

/**
 * Result Display Windows
 * @author Tiancheng Zhang
 *
 */
public class ResultDisplayWindow extends javax.swing.JFrame{
    /**
	 * 
	 */
	private static final long serialVersionUID = 2107023786353558649L;
	private String projectName;
	
	/**default trigging event weight*/
	private boolean defaultTriggingEventWeight;
	
	/**Trigging alternative plan weight*/
	private double trAltWeight;
	
	/** Creates new form ResultDisplayWindow */
    public ResultDisplayWindow(String projectName, boolean defaultTriggingEventWeight, double trAltWeight) {
    	this.defaultTriggingEventWeight = defaultTriggingEventWeight;
    	this.trAltWeight = trAltWeight;
        initComponents();
        this.projectName = projectName;
    	Toolkit tk=Toolkit.getDefaultToolkit();
    	Dimension screenSize=tk.getScreenSize();
    	int screenHeight=screenSize.height;
    	int screenWidth=screenSize.width;
    	this.setLocation((screenWidth/2)-(this.getWidth()/2), screenHeight/2 - (this.getHeight()/2));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jLabel1.setText("Agent Reactiveness List:");

        tableModelResult = new DefaultTableModel( new Object [][]{
        }, new String [] {
            "Agent", "Reactiveness"});
        
        jTable1.setModel(tableModelResult);
        
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("Recalculate");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jButton2.setText("Close");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(263, Short.MAX_VALUE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(43, 43, 43))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)))
        );

        pack();
    }// </editor-fold>

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
        DriverMain dm = new DriverMain(projectName, defaultTriggingEventWeight, trAltWeight);
        dm.run();
        this.dispose();
    }

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
    	this.dispose();
    }
    
    /**
     * get table model result
     * @return DefaultTableModel
     */
    public DefaultTableModel getTableModelResult()
    {
    	return tableModelResult;
    }

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private DefaultTableModel tableModelResult;
    // End of variables declaration
}
